﻿@functions {
    public enum DisplayTypes {
        JavaScript,
        Button,
        All
    }

    public enum Languages {
        Arabic,
        Bulgarian,
        Catalan,
        ChineseSimplified,
        ChineseTraditional,
        Croatian,
        Czech,
        Danish,
        Dutch,
        EnglishUS,
        EnglishUK,
        Estonian,
        Filipino,
        Finnish,
        French,
        German,
        Greek,
        Hebrew,
        Hindi,
        Hungarian,
        Indonesian,
        Italian,
        Japanese,
        Korean,
        Latvian,
        Lithuanian,
        Malay,
        Norwegian,
        Persian,
        Polish,
        PortugueseBrazil,
        PortuguesePortugal,
        Romanian,
        Russian,
        Serbian,
        Swedish,
        Slovak,
        Slovenian,
        Spanish,
        SpanishLatinAmerica,
        Thai,
        Turkish,
        Ukrainian,
        Vietnamese
    }

    public enum Sizes {
        Small,
        Standard,
        Medium,
        Tall
    }
    
    ///<summary>
    /// Returns the associated language code for the specified language
    ///</summary>
    ///<param name="language">The language code for the provided language.</param>
    public static string GetLanguageCode(Languages language) {
        switch (language) {
            case Languages.Arabic:
                return "ar";
            case Languages.Bulgarian:
                return "bg";
            case Languages.Catalan:
                return "ca";
            case Languages.ChineseSimplified:
                return "zh-CN";
            case Languages.ChineseTraditional:
                return "zh-TW";
            case Languages.Croatian:
                return "hr";
            case Languages.Czech:
                return "cs";
            case Languages.Danish:
                return "da";
            case Languages.Dutch:
                return "nl";
            case Languages.EnglishUS:
                return "en-US";
            case Languages.EnglishUK:
                return "en-GB";
            case Languages.Estonian:
                return "et";
            case Languages.Filipino:
                return "fil";
            case Languages.Finnish:
                return "fi";
            case Languages.French:
                return "fr";
            case Languages.German:
                return "de";
            case Languages.Greek:
                return "el";
            case Languages.Hebrew:
                return "iw";
            case Languages.Hindi:
                return "hi";
            case Languages.Hungarian:
                return "hu";
            case Languages.Indonesian:
                return "id";
            case Languages.Italian:
                return "it";
            case Languages.Japanese:
                return "ja";
            case Languages.Korean:
                return "ko";
            case Languages.Latvian:
                return "lv";
            case Languages.Lithuanian:
                return "lt";
            case Languages.Malay:
                return "ms";
            case Languages.Norwegian:
                return "no";
            case Languages.Persian:
                return "fa";
            case Languages.Polish:
                return "pl";
            case Languages.PortugueseBrazil:
                return "pt-BR";
            case Languages.PortuguesePortugal:
                return "pt-PT";
            case Languages.Romanian:
                return "ro";
            case Languages.Russian:
                return "ru";
            case Languages.Serbian:
                return "sr";
            case Languages.Swedish:
                return "sv";
            case Languages.Slovak:
                return "sk";
            case Languages.Slovenian:
                return "sl";
            case Languages.Spanish:
                return "es";
            case Languages.SpanishLatinAmerica:
                return "es-419";
            case Languages.Thai:
                return "th";
            case Languages.Turkish:
                return "tr";
            case Languages.Ukrainian:
                return "uk";
            case Languages.Vietnamese:
                return "vi";
            default:
                return "";
        }
    }

    ///<summary>
    /// Returns the associated size code for the specified size
    ///</summary>
    ///<param name="language">The size code for the provided language.</param>
    public static string GetSizeCode(Sizes size) {
        switch (size) {
            case Sizes.Small:
                return "small";
            case Sizes.Medium:
                return "medium";
            case Sizes.Standard:
                return "standard";
            case Sizes.Tall:
                return "tall";
            default:
                return "standard";
        }
    }

}

@*
Summary:
    Shows a Google +1 button.

Parameter: language
    The language to use when displaying the button. Defaults to English (US).
Parameter: size
    The size to use when displaying the button. Defaults to Standard.
Parameter: display
    Whether to output the JavaScript block (DisplayTypes.JavaScript), the +1 button (DisplayTypes.Button), or both (DisplayTypes.All, default)
*@
@helper PlusOneButton(
            Languages language = Languages.EnglishUS,
            Sizes size = Sizes.Standard,
            DisplayTypes display = DisplayTypes.All) {
    var languageCode = new HtmlString(!GetLanguageCode(language).IsEmpty() ? "{" + string.Format("lang: '{0}'", GetLanguageCode(language)) + "}" : "");
    var sizeAttribute = new HtmlString(!GetSizeCode(size).IsEmpty() && GetSizeCode(size) != "standard" ? string.Format(" size=\"{0}\"", GetSizeCode(size)) : "");

  if (display == DisplayTypes.JavaScript || display == DisplayTypes.All) {
<script type="text/javascript" src="http://apis.google.com/js/plusone.js">
  @languageCode
</script>
  }

  if (display == DisplayTypes.Button || display == DisplayTypes.All) {
<g:plusone>@sizeAttribute></g:plusone>
  }
}

